Return to start page
Core/General/Struct Signal.j
1 /// Provides a simple signal template struct (oriented on Qt and the Boost signal library).
2 /// Does not support signal return values.
3 /// @author Tamino Dauth
4 library AStructCoreGeneralSignal requires AStructCoreGeneralVector, optional ALibraryCoreDebugMisc
5
6 //! textmacro A_SIGNAL takes STRUCTPREFIX, NAME, PARAMETERS, PARAMETERNAMES
7 function interface $NAME$FunctionInterface takes $PARAMETERS$ returns nothing
8
9 $STRUCTPREFIX$ struct $NAME$
10 private AIntegerVector m_slots
11 private ABooleanVector m_slotIsBlocked
12
13 public method connect takes $NAME$FunctionInterface slot returns integer
14 call this.m_slots.pushBack(slot)
15 call this.m_slotIsBlocked.pushBack(false)
16 return this.m_slots.backIndex()
17 endmethod
18
19 public method disconnectByIndex takes integer index returns nothing
20 call this.m_slots.erase(index)
21 call this.m_slotIsBlocked.erase(index)
22 endmethod
23
24 public method disconnect takes $NAME$FunctionInterface slot returns integer
25 local integer index = this.m_slots.find(slot)
26 if (index != -1) then
27 call this.disconnectByIndex(index)
28 endif
29 return index
30 endmethod
31
32 public method isConnected takes $NAME$FunctionInterface slot returns boolean
33 return this.m_slots.contains(slot)
34 endmethod
35
36 public method isBlocked takes $NAME$FunctionInterface slot returns boolean
37 local integer index = this.m_slots.find(slot)
38 if (index == -1) then
39 debug call Print("Can't check if slot is blocked because it does not exist.")
40 return true
41 endif
42 return this.m_slotIsBlocked[index]
43 endmethod
44
45 public method isBlockedByIndex takes integer index returns boolean
46 return this.m_slotIsBlocked[index]
47 endmethod
48
49 public method emit takes $PARAMETERS$ returns nothing
50 local integer i = 0
51 loop
52 exitwhen (i == this.m_slots.size())
53 if (not this.m_slotIsBlocked[i]) then
54 call $NAME$FunctionInterface(this.m_slots[i]).execute($PARAMETERNAMES$)
55 endif
56 set i = i + 1
57 endloop
58 endmethod
59 endstruct
60 //! endtextmacro
61
62 endlibrary